package 线程创建.Runnable接口;


import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class testThread2 implements Runnable{
    String url;
    String name;
    public testThread2 (String url,String name){
        this.name=name;
        this.url=url;
    }
    @Override
    public void run() {
//        super.run();
        wedDownloader wedDownloader = new wedDownloader();
        wedDownloader.downloader(url,name);
        System.out.println("下载的文件明为："+name);
    }

    public static void main(String[] args) {
        testThread2 t1 = new testThread2("http://images.china.cn/site1000/2020-08/03/5971d9dc-3cd4-4cec-ad8d-5a6dcfdfc6fd.jpg","冰川1.jpg");
        testThread2 t2 = new testThread2("http://images.china.cn/site1000/2020-08/03/3e0b7ff7-6860-4fec-8387-9ecdc17887fc.jpg","冰川2.jpg");
        testThread2 t3 = new testThread2("http://images.china.cn/site1000/2020-08/03/5faadc7d-4671-46de-a75d-eaadc4d30359.jpg","冰川3.jpg");

        new Thread(t1).start();
        new Thread(t2).start();
        new Thread(t3).start();

    }
}

//下载器
class wedDownloader{
    //下载方法
    public void downloader(String url,String name){
        try {
            //下载commons-io工具提供的下载方法
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
